﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace ObjectCache.Tokens
{
    public class InstanceToken : BaseToken
    {
        private WeakReference mInstance;
        public InstanceToken(object instance)
        {
            mInstance = new WeakReference(instance);
        }

        public override bool IsCurrent
        {
            get
            {
                var obj = mInstance.Target;
                if (obj == null)
                    return false;
                else
                {
                    var ctrl = obj as Control;
                    if (ctrl == null)
                        return true;
                    else
                    {
                        return ctrl.Created;
                    }
                }
            }
        }
    }
}
